﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:Triggers="clr-namespace:ChristianMoser.WpfInspector.Services.Triggers" 
                    xmlns:Resources="clr-namespace:ChristianMoser.WpfInspector.Services.Resources" xmlns:Controls="clr-namespace:ChristianMoser.WpfInspector.UserInterface.Controls">

    <Style TargetType="{x:Type Controls:ItemControl}">
        <Setter Property="Background" Value="#f7f7f7" />
        <Setter Property="BorderBrush" Value="#d4d4d4" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:ItemControl}">
                    <Border Background="{TemplateBinding Background}" CornerRadius="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" Margin="2">
                        <Grid>
                            <Border Background="#0F000000" Height="18" VerticalAlignment="Top" />
                            <ContentPresenter TextBlock.FontWeight="Bold" TextBlock.FontSize="11" TextBlock.Foreground="#b5b5b5" Content="{TemplateBinding Header}" VerticalAlignment="Top" Margin="20,0,0,0" />
                            <Image x:Name="icon" Source="/Inspector;component/UserInterface/VisualResources/Images/resourceitem.png" Margin="4,2,0,0"
                                   VerticalAlignment="Top" HorizontalAlignment="Left" Width="12" Height="12" />
                            <ContentPresenter Content="{TemplateBinding Content}" Margin="4,16,4,4" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="ItemType" Value="{x:Static Controls:ItemType.Trigger}">
                            <Setter TargetName="icon" Property="Source" Value="/Inspector;component/UserInterface/VisualResources/Images/triggeritem.png" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <!-- ========================= -->
    <!-- Values                    -->
    <!-- ========================= -->

    <DataTemplate DataType="{x:Type Brush}" >
        <Border Background="{Binding}" BorderThickness="1" CornerRadius="1" 
                BorderBrush="{DynamicResource DefaultBorderBrush}" HorizontalAlignment="Left" 
                VerticalAlignment="Stretch" Height="20" Width="100" />
    </DataTemplate>

    <DataTemplate DataType="{x:Type Geometry}" >
        <Path Data="{Binding}" MaxWidth="32" MaxHeight="32" Stroke="Black" StrokeThickness="1" Fill="Gray"  />
    </DataTemplate>

    <DataTemplate DataType="{x:Type Drawing}" >
        <Image MaxWidth="32" MaxHeight="32" StretchDirection="DownOnly" >
            <Image.Source>
                <DrawingImage Drawing="{Binding}" />
            </Image.Source>
        </Image>
    </DataTemplate>
  
    <DataTemplate DataType="{x:Type Style}" >
        <Controls:StyleVisualizer StyleToVisualize="{Binding}" >
            <Controls:StyleVisualizer.Template>
                <ControlTemplate TargetType="{x:Type Controls:StyleVisualizer}">
                    <Image Source="{TemplateBinding StyledElement}" Width="{TemplateBinding ElementWidth}" Height="{TemplateBinding ElementHeight}" />
                </ControlTemplate>
            </Controls:StyleVisualizer.Template>
        </Controls:StyleVisualizer>
    </DataTemplate>


    <!-- ========================= -->
    <!-- Setters                   -->
    <!-- ========================= -->

  

    <DataTemplate DataType="{x:Type Triggers:SetterItem}">

        <Grid Margin="2" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" SharedSizeGroup="key" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <TextBlock x:Name="key" Text="{Binding Property, StringFormat='{}{0}:'}" />
            <ContentPresenter x:Name="value" Grid.Column="1" Content="{Binding Value}" Margin="4,0,0,0" />
        </Grid>

        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsOverridden}" Value="True">
                <Setter TargetName="key" Property="TextBlock.TextDecorations" Value="Strikethrough" />
                <Setter TargetName="value" Property="TextBlock.TextDecorations" Value="Strikethrough" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <!-- ========================= -->
    <!-- Triggers                  -->
    <!-- ========================= -->

    <DataTemplate DataType="{x:Type Triggers:TriggerItemBase}">
        <Controls:ItemControl x:Name="itemControl" Header="{Binding TriggerType}" ItemType="Trigger">
            <StackPanel>
                <TextBlock Text="Conditions" Margin="4,4,4,0" />
                <ItemsControl Margin="8,4" ItemsSource="{Binding Conditions}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" >
                                <Image x:Name="image" Source="/Inspector;component/UserInterface/VisualResources/Images/inactive.png" Height="16" Width="16" />
                                <TextBlock x:Name="conditionText" Text="{Binding Condition}" />
                            </StackPanel>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding IsActive}" Value="True">
                                    <Setter Property="Source" Value="/Inspector;component/UserInterface/VisualResources/Images/active.png" TargetName="image" />
                                    <Setter Property="FontWeight" Value="Bold" TargetName="conditionText" />
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <TextBlock Text="Setters" Margin="4,4,4,0" />
                <ItemsControl Margin="8,4" ItemsSource="{Binding Setters}" />
            </StackPanel>
        </Controls:ItemControl>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsActive}" Value="True">
                <Setter Property="Background" Value="{DynamicResource ActiveTriggerBrush}" TargetName="itemControl" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <!-- ========================= -->
    <!-- Resources                 -->
    <!-- ========================= -->

    <ControlTemplate x:Key="PropertyContentControlTemplate" TargetType="ContentControl">

        <TextBlock Margin="4,2" Foreground="{DynamicResource DefaultForegroundBrush}" VerticalAlignment="Center" Text="{Binding Name, StringFormat='{}{{DynamicResource {0}}}'}" TextTrimming="CharacterEllipsis" >
            <TextBlock.ToolTip>
                <ContentPresenter Grid.Column="1" Margin="4,0,0,0" VerticalAlignment="Center" />    
            </TextBlock.ToolTip>
        </TextBlock>
    </ControlTemplate>


    <DataTemplate DataType="{x:Type Resources:BrushResourceItem}">
        <ContentControl Template="{StaticResource PropertyContentControlTemplate}">
            <Border BorderBrush="{DynamicResource DefaultBorderBrush}" BorderThickness="1" Background="{Binding Value}" Height="20" Margin="8,3" MinWidth="80"  >
                <Border.ToolTip>
                    <ToolTip>
                        <ItemsControl ItemsSource="{Binding BrushStops}">
                            <ItemsControl.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"  />
                                            <ColumnDefinition Width="*"  />
                                        </Grid.ColumnDefinitions>
                                        <TextBlock Foreground="{DynamicResource DefaultForegroundBrush}" Text="{Binding Position}" Margin="4" />
                                        <TextBlock Foreground="{DynamicResource DefaultForegroundBrush}" Grid.Column="1" Text="{Binding ColorText}" Margin="4" />
                                    </Grid>
                                </DataTemplate>
                            </ItemsControl.ItemTemplate>
                        </ItemsControl>
                    </ToolTip>
                </Border.ToolTip>
            </Border>
        </ContentControl>
    </DataTemplate>

    <DataTemplate DataType="{x:Type Resources:ColorResourceItem}">
        <ContentControl Template="{StaticResource PropertyContentControlTemplate}">
            <Border BorderBrush="{DynamicResource DefaultBorderBrush}" BorderThickness="1" Background="{Binding Value}" Height="18" Margin="8,3" ToolTip="{Binding Value}" />
        </ContentControl>
    </DataTemplate>

    <DataTemplate DataType="{x:Type Resources:GeometryResourceItem}">
        <ContentControl Template="{StaticResource PropertyContentControlTemplate}">
            <Image MaxHeight="30" Stretch="None">
                <Image.Source>
                    <DrawingImage >
                        <DrawingImage.Drawing>
                            <GeometryDrawing Brush="{DynamicResource DefaultHighlightBrush}" Geometry="{Binding Value}">
                                <GeometryDrawing.Pen>
                                    <Pen Brush="{DynamicResource DefaultForegroundBrush}" Thickness="1" />
                                </GeometryDrawing.Pen>
                            </GeometryDrawing>
                        </DrawingImage.Drawing>
                    </DrawingImage>
                </Image.Source>
            </Image>
        </ContentControl>
    </DataTemplate>

    <DataTemplate DataType="{x:Type Resources:DrawingResourceItem}">
        <ContentControl Template="{StaticResource PropertyContentControlTemplate}">
            <Image MaxHeight="30" Stretch="None">
                <Image.Source>
                    <DrawingImage Drawing="{Binding Value}" />
                </Image.Source>
            </Image>
        </ContentControl>
    </DataTemplate>

    <DataTemplate DataType="{x:Type Resources:ResourceItem}">
        <ContentControl Template="{StaticResource PropertyContentControlTemplate}">
            <TextBlock Foreground="{DynamicResource DefaultForegroundBrush}" Grid.Column="1" Text="{Binding Value}" />
        </ContentControl>
    </DataTemplate>

</ResourceDictionary>